/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.max.oti.system.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

/**
 *
 * @author max
 */
@Entity
@Table(name = "practice", catalog = "dbfiis", schema = "public")
@XmlRootElement
public class Practice implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Basic(optional = false)
    @Size(min = 1, max = 15)
    @Column(name = "code_alumn")
    private String codeAlumn;
    @Basic(optional = false)
    @Size(max = 100)
    @Column(name = "name_area")
    private String nameArea;
    @Size(max = 50)
    @Column(name = "inmmediative_boss")
    private String inmmediativeBoss;
    @Basic(optional = false)
    @Size(min = 1, max = 300)
    @Column(name = "title_project")
    private String titleProject;
    @Basic(optional = false)
    @Size(min = 1, max = 350)
    @Column(name = "summary_project")
    private String summaryProject;
    @Column(name = "start_date")
    @Temporal(TemporalType.DATE)
    private Date startDate;
    @Column(name = "end_date")
    @Temporal(TemporalType.DATE)
    private Date endDate;
    @Column(name = "amplificated")
    @Basic(optional = false)
    private boolean amplificated;
    @Basic(optional = false)
    @Size(min = 1, max = 350)
    @Column(name = "names")
    private String names;
    @Basic(optional = false)
    @Column(name = "credit")
    private Integer credit;
    @JoinColumn(name = "id_adviser_practice", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private AdviserPractice idAdviserPractice;
    @OneToMany(mappedBy = "idPractice")
    @Cascade({CascadeType.DELETE_ORPHAN, CascadeType.SAVE_UPDATE, CascadeType.DELETE})
    private List<ReportPractice> reportPracticeList = new ArrayList<ReportPractice>();
    @OneToMany(mappedBy = "idPractice")
    @Cascade({CascadeType.DELETE_ORPHAN, CascadeType.SAVE_UPDATE, CascadeType.DELETE})
    private List<FunctionPractice> functionPracticeList = new ArrayList<FunctionPractice>();
    @OneToMany(mappedBy = "idPractice")
    @Cascade({CascadeType.DELETE_ORPHAN, CascadeType.SAVE_UPDATE, CascadeType.DELETE})
    private List<SupervisionPractice> supervisionPracticeList = new ArrayList<SupervisionPractice>();
    @OneToMany(mappedBy = "idPractice")
    @Cascade({CascadeType.DELETE_ORPHAN, CascadeType.SAVE_UPDATE, CascadeType.DELETE})
    private List<HistoryPractice> historyPracticeList = new ArrayList<HistoryPractice>();
    @OneToMany(mappedBy = "idPractice")
    @Cascade({CascadeType.DELETE_ORPHAN, CascadeType.SAVE_UPDATE, CascadeType.DELETE})
    private List<AmplificationPractice> amplificationPracticeList = new ArrayList<AmplificationPractice>();
    @OneToMany(mappedBy = "idPractice")
    @Cascade({CascadeType.DELETE_ORPHAN, CascadeType.SAVE_UPDATE, CascadeType.DELETE})
    private List<SustentationPractice> sustentationPracticeList = new ArrayList<SustentationPractice>();
    @JoinColumn(name = "id_company", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private Company idCompany;

    ///////////TRANSITABLE////////////
    @Transient
    private HistoryPractice idHistoryPractice;
    @Transient
    private Date dateFinal;
    
    public Practice() {
    }

    public Practice(Integer id) {
        this.id = id;
    }

    public Practice(Integer id, String codeAlumn, String nameArea, String titleProject, String summaryProject) {
        this.id = id;
        this.codeAlumn = codeAlumn;
        this.nameArea = nameArea;
        this.titleProject = titleProject;
        this.summaryProject = summaryProject;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getCodeAlumn() {
        return codeAlumn;
    }

    public void setCodeAlumn(String codeAlumn) {
        this.codeAlumn = codeAlumn;
    }

    public String getNameArea() {
        return nameArea;
    }

    public void setNameArea(String nameArea) {
        this.nameArea = nameArea;
    }

    public String getInmmediativeBoss() {
        return inmmediativeBoss;
    }

    public void setInmmediativeBoss(String inmmediativeBoss) {
        this.inmmediativeBoss = inmmediativeBoss;
    }

    public String getTitleProject() {
        return titleProject;
    }

    public String getNames() {
        return names;
    }

    public void setNames(String names) {
        this.names = names;
    }

    public void setTitleProject(String titleProject) {
        this.titleProject = titleProject;
    }

    public String getSummaryProject() {
        return summaryProject;
    }

    public void setSummaryProject(String summaryProject) {
        this.summaryProject = summaryProject;
    }

    public Date getStartDate() {
        return startDate;
    }

    public Integer getCredit() {
        return credit;
    }

    public void setCredit(Integer credit) {
        this.credit = credit;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }
    
    public HistoryPractice getIdHistoryPractice() {
        if(this.getHistoryPracticeList() != null && !this.getHistoryPracticeList().isEmpty()){
            this.idHistoryPractice = this.getHistoryPracticeList().get(this.getHistoryPracticeList().size() - 1);
        }
        return idHistoryPractice;
    }

    public boolean isAmplificated() {
        return amplificated;
    }

    public void setAmplificated(boolean amplificated) {
        this.amplificated = amplificated;
    }

    public void setIdHistoryPractice(HistoryPractice idHistoryPractice) {
        this.idHistoryPractice = idHistoryPractice;
    }

    public Date getDateFinal() {
//        if(getAmplificationPracticeList().isEmpty()) {
//            dateFinal = endDate;
//        } else {
//            dateFinal = getAmplificationPracticeList().get(getAmplificationPracticeList().size() - 1).getNewDate();
//        }
        return dateFinal;
    }

    public void setDateFinal(Date dateFinal) {
        this.dateFinal = dateFinal;
    } 

    public AdviserPractice getIdAdviserPractice() {
        return idAdviserPractice;
    }

    public void setIdAdviserPractice(AdviserPractice idAdviserPractice) {
        this.idAdviserPractice = idAdviserPractice;
    }

    @XmlTransient
    public List<ReportPractice> getReportPracticeList() {
        return reportPracticeList;
    }

    public void setReportPracticeList(List<ReportPractice> reportPracticeList) {
        this.reportPracticeList = reportPracticeList;
    }

    @XmlTransient
    public List<FunctionPractice> getFunctionPracticeList() {
        return functionPracticeList;
    }

    public void setFunctionPracticeList(List<FunctionPractice> functionPracticeList) {
        this.functionPracticeList = functionPracticeList;
    }

    @XmlTransient
    public List<SupervisionPractice> getSupervisionPracticeList() {
        return supervisionPracticeList;
    }

    public void setSupervisionPracticeList(List<SupervisionPractice> supervisionPracticeList) {
        this.supervisionPracticeList = supervisionPracticeList;
    }

    @XmlTransient
    public List<HistoryPractice> getHistoryPracticeList() {
        return historyPracticeList;
    }

    public void setHistoryPracticeList(List<HistoryPractice> historyPracticeList) {
        this.historyPracticeList = historyPracticeList;
    }
    
    @XmlTransient
    public List<AmplificationPractice> getAmplificationPracticeList() {
        return amplificationPracticeList;
    }

    public void setAmplificationPracticeList(List<AmplificationPractice> amplificationPracticeList) {
        this.amplificationPracticeList = amplificationPracticeList;
    }
    @XmlTransient
    public List<SustentationPractice> getSustentationPracticeList() {
        return sustentationPracticeList;
    }

    public void setSustentationPracticeList(List<SustentationPractice> sustentationPracticeList) {
        this.sustentationPracticeList = sustentationPracticeList;
    }

    public Company getIdCompany() {
        return idCompany;
    }

    public void setIdCompany(Company idCompany) {
        this.idCompany = idCompany;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Practice)) {
            return false;
        }
        Practice other = (Practice) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.max.oti.system.model.Practice[ id=" + id + " ]";
    }
    
}
